package com.lankystar.sos.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.sos.dao.IResponseDao;
import com.lankystar.sos.model.ResponseOrder;

@Repository
public class ResponseDaoImpl implements IResponseDao{

	@Autowired
	private SessionFactory sf;
	public Session getSession(){
		System.err.println("session开启！！");
		return sf.getCurrentSession();
	}
	@Override
	public void addResponse(ResponseOrder record) {
		getSession().save(record);
	}
	@Override
	public void updateResponse(ResponseOrder record) {
		getSession().update(record);
	}
	@Override
	public Object[] selectRespOrderAndSosOrder(Integer responseId) {
		String sql = "from ResponseOrder resp join resp.respStatus respStatus join resp.user u join u.userApprove ua join ua.userType ut join resp.sosOrder sos join sos.user su where resp.responseId=?";
		Object[] ob = (Object[]) getSession().createQuery(sql).setInteger(0, responseId).uniqueResult();
		return ob;
	}

}
